package cn.dengta.webapp.trade.dto;

import java.io.Serializable;

import cn.dengta.context.rpc.CachedConfig;
import cn.dengta.context.rpc.CachedConfigManager;
import cn.dengta.webapp.trade.dto.common.PayConfig;
import lombok.Getter;
import lombok.Setter;

/**
 * 校验公共配置
 */
@Getter
@Setter
public class TradeCommonConfig implements Serializable {

	/** 支付渠道配置 */
	private PayConfig payConfig;

	public static PayConfig buildPayConfig() {
		return cache().get().getPayConfig();
	}

	public static TradeCommonConfig getDefault() {
		final TradeCommonConfig config = new TradeCommonConfig();
		config.setPayConfig(PayConfig.getDefault());
		return config;
	}

	public static CachedConfig<TradeCommonConfig> cache() {
		return TradeCommonConfig.InstanceHolder.instance;
	}

	private static final class InstanceHolder {

		static final CachedConfig<TradeCommonConfig> instance = CachedConfigManager.create(TradeCommonConfig.class, TradeCommonConfig::getDefault);

	}

}
